import { reqGetUserAdress, reqGetShopCartOrder } from '@/api'

let state = {
  userAdress: [],
  shopcartOrder: {},
  orderId: '2312'
}

let mutations = {
  GETUSERADRESS(state, data) {
    state.userAdress = data
  },
  GETSHOPCARTORDER(state, data) {
    state.shopcartOrder = data
  },
  SETORDERNUM(state, num) {
    state.orderId = num
  }
}

let actions = {
  // 地址
  async getUserAdress({ commit }) {
    let res = await reqGetUserAdress()
    if (res.code == 200) {
      commit('GETUSERADRESS', res.data)
    } else {
      return { ok: false, msg: res.message }
    }
  },

  // 获取个购物车订单信息
  async getShopcartOrder({ commit }) {
    const result = await reqGetShopCartOrder()
    if (result.code == 200) {
      commit('GETSHOPCARTORDER', result.data)
    } else {
      return { ok: false, msg: result.message }
    }
  },

  // 存入订单号
  setOrderNumber({ commit }, num) {
    commit('SETORDERNUM', num)
  }
}

let getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}
